home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / __MANDEL / TCL_SOUR / CDWSWITC.C < prev    next >
Text File  |  1992-05-30  |  4KB  |  123 lines

  1. /******************************************************************************
  2.  CDWSwitchboard.c
  3.  
  4.                             The DWSwitchboard Class
  5.         
  6.         Retrieves events from the Toolbox event queue and passes messages
  7.         to the proper objects for responding to them.
  8.     
  9.     SUPERCLASS = CSwitchboard
  10.     
  11.     DW CHANGES
  12.     [
  13.         - changed the way mouseMoved events were processed... CSwitchboard
  14.           essentially ignored the mouseMoved event opting instead to
  15.           call DispatchCursor for each and every event.
  16.     ]
  17.     
  18.  ******************************************************************************/
  19.  
  20. #include "Global.h"
  21. #include "TBUtilities.h"
  22. #include "CApplication.h"
  23. #include "CDesktop.h"
  24. #include "CBartender.h"
  25. #include "CWindow.h"
  26. #include "CDWSwitchboard.h"
  27. #include "Commands.h" 
  28. #include "Constants.h"
  29. #include "CAppleEvent.h"
  30. #include "AppleEvents.h"
  31. #include "Editions.h"
  32.  
  33. #include "EPPC.h"
  34.  
  35. /*** Global Variables ***/
  36.     
  37. extern CApplication    *gApplication;        /* Application object                */
  38. extern CDesktop        *gDesktop;            /* The visible Desktop                */
  39. extern CBartender    *gBartender;        /* Manages all menus                */
  40. extern CBureaucrat    *gGopher;            /* First in line to get commands    */
  41. extern EventRecord    gLastMouseDown;        /* Previous mouse down event        */
  42. extern EventRecord    gLastMouseUp;        /* Previous mouse up event            */
  43. extern CView        *gLastViewHit;        /* Last view clicked in                */
  44. extern long            gSleepTime;            /* Max time between events            */
  45.  
  46. /*** Class Constants ***/
  47.  
  48. #define        MouseMovedEvt        0xFA    /* Mouse moved event code            */
  49. #define        SuspendResumeEvt    0x01    /* Suspend/Resume event code        */
  50. #define        ResumeEvtMask        0x1        /* Supend or Resume selector        */
  51. #define        ConvertScrapMask    0x2        /* Scrap conversion flag            */
  52.  
  53. /******************************************************************************
  54.  ProcessEvent
  55.  
  56.         Get the next event in the queue and call the proper method to
  57.         handle it.
  58.         
  59.     TCL 1.1: Previously, ProcessEvent get the event itself and did its own
  60.              dispatching. It now calls GetAnEvent to get an event from
  61.              the queue and DispatchEvent to handle the event. This
  62.              makes the event dispatch mechanism easier to modify, as
  63.              well as making integration with AppleEvents easier.
  64.  ******************************************************************************/
  65.  
  66. void    CDWSwitchboard::ProcessEvent( void)
  67. {
  68.     EventRecord            macEvent;        /* Mac Event to be processed        */
  69.     Boolean                isMyEvent;        /* Should program handle event?        */
  70.  
  71.                                         /* Get an event from the queue        */
  72.     isMyEvent = GetAnEvent( &macEvent);
  73.     
  74.     if (isMyEvent)                         /* We must respond to this event    */
  75.     {            
  76.         DispatchEvent( &macEvent);        
  77.     } 
  78.     else 
  79.     {                                    /* No action required                */
  80.         DoIdle( &macEvent);
  81.     }
  82. }
  83.  
  84. /******************************************************************************
  85.  DispatchEvent
  86.  
  87.     Dispatch the event to the appropriate handler.
  88.  ******************************************************************************/
  89.  
  90. void    CDWSwitchboard::DispatchEvent( EventRecord *macEvent)
  91. {
  92.     Point                mouseLoc;
  93.                                 
  94.  
  95.     switch (macEvent->what) {        /* Branch of the type of event        */
  96.     
  97.         case osEvt:
  98.         
  99.                                     /* Event type is stored in the        */
  100.                                     /*   high byte of the event message    */
  101.                                     /*   Typecast to unsigned long so    */
  102.                                     /*   we won't get sign extension    */
  103.                                     /*   when the bits are shifted        */
  104.             switch ((unsigned long)macEvent->message >> 24) {
  105.             
  106.                 case MouseMovedEvt:
  107.                                     /* Since we adjust the cursor shape    */
  108.                                     /*   before handling an event, we    */
  109.                                     /*   can just idle here                */
  110.     
  111.                     gDesktop->Prepare();
  112.                     GetMouse(&mouseLoc);
  113.                     gDesktop->DispatchCursor(mouseLoc, mouseRgn);
  114.                     return;
  115.             }
  116.             break;
  117.             
  118.     }
  119.     
  120.     CSwitchboard::DispatchEvent(macEvent);
  121. }
  122.  
  123.